<?php 
 class IndexAction extends Action{
 	
 	  public function index(){ //显示登录页面
          	header("Content-type:text/vnd.wap.wml");          
          	$getUrl=$_GET['trueurl'];
          	if(empty($getUrl)){
          		$getUrl=$_GET['tUrl'];
          		if(empty($getUrl)){
          		header("location:http://www.sina.com.cn");
          		}
          		$userId=$_GET['uId'];
          			$back=base64_decode($getUrl);
		            $back=split("/",$back);
	            	$this->assign("backUrl",$back[0]);
          		$this->assign("trueUrl",$getUrl);	 
          		$this->assign("userId",$userId);	 
          		$this->display("index2");          		
          	}        	
          		$back=base64_decode($getUrl);
		          $back=split("/",$back);
		          $this->assign("backUrl",$back[0]);
          	$this->assign("trueUrl",$getUrl);	    
	          $this->display(); 
	  }

    public function index2(){//显示用户的基本信息 
   	
   	$trueUrl=$_GET['tUrl'];
		$userId=$_GET['uId'];    
		$back=base64_decode($trueUrl);
		$back=split("/",$back);
		$this->assign("backUrl",$back[0]);
		$this->assign("trueUrl",$trueUrl);
		
    	if(empty($userId)){
    		$this->assign("请您先登录");    		
    		$this->display("index");
    	}         
    	$this->assign("userId",$userId);
	    $user=D("Mobileuser"); 
	    $m_id=$userId;    
      $data=$user->where("uid=".$m_id)->find();
      $this->assign("id",$data['name']);              
      $this->assign("mScore",$data['score']);           
	    $this->display(); 
	  }
    public function  register(){ //注册
     $name=$_POST['name']; 
     $passwd=$_POST['password'];
     $repasswd=$_POST['repassword'];
     $trueUrl=$_POST['tUrl'];    
     if(empty($trueUrl)){
     	 $trueUrl=$_GET['trueUrl'];
     	 $userId=$_GET['userId'];
     	 $userf=D("Mobileuser");   
       $dataf=$userf->where('uid='.$userId)->find();
        
        $this->assign("trueUrl",$trueUrl);
        $this->assign("userId",$userId);
        $this->assign("id",$dataf['name']);
        $this->assign("mScore",$dataf['score']);
        $this->display("index2");
        return ;
     }
     $this->assign("trueUrl",$trueUrl);
     if(empty($name)){
     	$message="用户名不能为空";
     	$this->assign("msg",$message);
     	$this->display("register");
     	return;
     } 
      
    if(empty($passwd)){
     	$message="密码不能为空";
     	$this->assign("username",$name);
     	$this->assign("msg",$message);
     	$this->display("register");
     	return ;
     }
     if($passwd!=$repasswd){
     	$message="确认密码与密码不一致";
     	$this->assign("username",$name);
     	$this->assign("msg",$message);
     	$this->display("register");
     	return;
     }          
     $user=D("Mobileuser");   
     $user=$user->where("name='".$name."'")->find();
     if(!empty($user['uid'])){
     $message="该用户名已经存在，请您选择别的用户名注册";
     $this->assign("msg",$message);	
     $this->display('register');     	
     return ;
    }
     $data = array();
     $mUser = D("Mobileuser");     
    	$data['name']=$name;
    	$data['pwd']=md5($passwd);
    	$data['score']=0.0;
    	$data['last_consume_time']=date('Y-m-d H-i-s');    	
    	$mUser->create($data);
    	$uid=$mUser->add();   
    	$this->assign("userId",$uid);    	
    	$this->assign("mScore",$data['score']);
    	$this->assign("id",$name);   
    	$this->display("index2");
 	 	}
  	 	
 	 	public function bef_register(){//显示注册页面
 	 			$trueUrl=$_GET['tUrl'];
 	 			$userId=$_GET['uId'];
 	 			$this->assign("trueUrl",$trueUrl); 	 
 	 			if(!empty($userId)){
 	 				$userf=D("Mobileuser");     
          $dataf=$userf->where("uid=".$userId)->find();    
      	  $this->assign("id",$dataf['name']);   
      	  $this->assign("mScore",$dataf['score']);
 	 				
 	 				$this->assign("userId",$userId);
 	 				$this->display("index2");
 	 				return ;
 	 			}
 	 		$this->display("register");
 	 	}
 	  	 	
 	 	public function login(){//登录
 	 		$name=$_POST['name']; 
      $passwd=$_POST['password'];
      $trueUrl=$_POST['tUrl'];  
      $back=base64_decode($trueUrl);
		  $back=split("/",$back);
	  	$this->assign("backUrl",$back[0]);          
      if(empty($trueUrl)){
      	 $trueUrl=$_GET['tUrl'];
      	 $userId=$_GET['uId'];      	
      	 $userf=D("Mobileuser");     
         $dataf=$userf->where("uid=".$userId)->find(); 
         $back=base64_decode($trueUrl);
		     $back=split("/",$back);
	  	   $this->assign("backUrl",$back[0]); 
      	 $this->assign("id",$dataf['name']);   
      	 $this->assign("mScore",$dataf['score']);
      	 $this->assign("trueUrl",$trueUrl);
      	 $this->assign("userId",$userId);
      	 $this->display("index2");
      	 return ;      	
      }
      $this->assign("trueUrl",$trueUrl);
      $user=D("Mobileuser");     
      $data=$user->where("name='".$name."' and pwd='".md5($passwd)."'")->find();
      if(empty($data)){
      	$message="用户名或密码不正确！";
      	$this->assign("msg",$message);
      	$this->display("index");
      	return ;
      }else{
      	$this->assign("id",$name);   
      	$this->assign("mScore",$data['score']);
      	$this->assign("userId",$data['uid']);
        $this->display("index2");
      }
 	 		
 	 	}
 	 	
}
?>